<template>
  <div>
    <van-cell-group>
      <van-field
        :label="label"
        :value="value"
        @input="$emit('input', $event.trim())"
        @blur="blur"
        input-align="right"
        :placeholder="placeholder"
        :rules="rule"
      />
    </van-cell-group>
  </div>
</template>
<script>
import { checkName } from '../../utils/commonValidate'
const validateName = (name, errTipPrefix) => {
  if (Object.is(name.trim(), "")) {
    return `请输入${errTipPrefix}姓名`;
  }
  const result = checkName(name);
  console.log('===',result);
  if (result) {
    return errTipPrefix + result;
  }
  return result;
};
export default {
  props: {
    label: String,
    placeholder: String,
    value: String,
    index: [String, Number],
  },
  data() {
    return {
      errTipPrefix: `被保人${this.index}`
    };
  },
  computed: {
    rule() {
      return [
        {
          required: true,
          message: (val) => {        
            return validateName(val, this.errTipPrefix);
          },
          validator(val) {
            return !validateName(val, this.errTipPrefix);
          },
        },
      ];
    },
  },
  methods: {
    blur() {},
  },
};
</script> 
